package cuongnh.project.japanesediary.vocabulary.ui.wizard.page;

import org.eclipse.core.databinding.DataBindingContext;
import org.eclipse.core.databinding.beans.PojoProperties;
import org.eclipse.core.databinding.observable.value.IObservableValue;
import org.eclipse.jface.databinding.swt.WidgetProperties;
import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.TabFolder;
import org.eclipse.swt.widgets.TabItem;
import org.eclipse.swt.widgets.Text;
import org.eclipse.wb.swt.ResourceManager;

import cuongnh.project.japanesediary.vocabulary.model.Sentence;

public class NewSentenceWizardPage extends WizardPage {
	private DataBindingContext m_bindingContext;
	private Text txtVietnameseMeaning;
	private Text txtEnglishMeaning;
	private Text txtAudioFilePath;
	private Text txtSentence;
	private Sentence example;

	/**
	 * Create the wizard.
	 */
	public NewSentenceWizardPage(Sentence example) {
		super("wizardPage");
		setTitle("Create a new Sentence");
		setDescription("This wizard page is used to create a new Sentence");
		this.example = example;
	}

	/**
	 * Create contents of the wizard.
	 * @param parent
	 */
	public void createControl(Composite parent) {
		Composite container = new Composite(parent, SWT.NULL);

		setControl(container);
		container.setLayout(new GridLayout(3, false));
		
		Group grpSentence = new Group(container, SWT.NONE);
		grpSentence.setText("Sentence");
		GridData gd_grpSentence = new GridData(SWT.FILL, SWT.FILL, true, true, 3, 1);
		gd_grpSentence.heightHint = 76;
		grpSentence.setLayoutData(gd_grpSentence);
		grpSentence.setLayout(new GridLayout(3, false));
		
		txtSentence = new Text(grpSentence, SWT.BORDER | SWT.WRAP | SWT.V_SCROLL | SWT.MULTI);
		txtSentence.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 3, 1));
		
		Group grpMeaning = new Group(container, SWT.NONE);
		grpMeaning.setText("Meaning");
		GridData gd_grpMeaning = new GridData(SWT.FILL, SWT.FILL, true, true, 3, 1);
		gd_grpMeaning.widthHint = 564;
		gd_grpMeaning.heightHint = 127;
		grpMeaning.setLayoutData(gd_grpMeaning);
		grpMeaning.setLayout(new GridLayout(2, false));
		
		TabFolder tabFolder = new TabFolder(grpMeaning, SWT.NONE);
		GridData gd_tabFolder = new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1);
		gd_tabFolder.heightHint = 98;
		tabFolder.setLayoutData(gd_tabFolder);
		
		TabItem tbtmVietnamese = new TabItem(tabFolder, SWT.NONE);
		tbtmVietnamese.setImage(ResourceManager.getPluginImage("cuongnh.project.japanesediary.vocabulary", "icons/vietnam.jpg"));
		tbtmVietnamese.setText("Vietnamese");
		
		txtVietnameseMeaning = new Text(tabFolder, SWT.BORDER | SWT.WRAP | SWT.V_SCROLL | SWT.MULTI);
		tbtmVietnamese.setControl(txtVietnameseMeaning);
		
		TabItem tbtmEnglish = new TabItem(tabFolder, SWT.NONE);
		tbtmEnglish.setImage(ResourceManager.getPluginImage("cuongnh.project.japanesediary.vocabulary", "icons/england.jpg"));
		tbtmEnglish.setText("English");
		
		txtEnglishMeaning = new Text(tabFolder, SWT.BORDER | SWT.MULTI);
		tbtmEnglish.setControl(txtEnglishMeaning);
		
		Group grpAudioFilePath = new Group(container, SWT.NONE);
		grpAudioFilePath.setText("Audio file path");
		grpAudioFilePath.setLayout(new GridLayout(3, false));
		GridData gd_grpAudioFilePath = new GridData(SWT.FILL, SWT.CENTER, true, false, 3, 1);
		gd_grpAudioFilePath.widthHint = 556;
		grpAudioFilePath.setLayoutData(gd_grpAudioFilePath);
		
		txtAudioFilePath = new Text(grpAudioFilePath, SWT.BORDER);
		txtAudioFilePath.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1));
		
		Button btnBrowse = new Button(grpAudioFilePath, SWT.NONE);
		btnBrowse.setText("Browse");
		m_bindingContext = initDataBindings();
	}
	protected DataBindingContext initDataBindings() {
		DataBindingContext bindingContext = new DataBindingContext();
		//
		IObservableValue observeTextTxtSentenceObserveWidget = WidgetProperties.text(SWT.Modify).observe(txtSentence);
		IObservableValue sentenceExampleObserveValue = PojoProperties.value("sentence").observe(example);
		bindingContext.bindValue(observeTextTxtSentenceObserveWidget, sentenceExampleObserveValue, null, null);
		//
		IObservableValue observeTextTxtVietnameseMeaningObserveWidget = WidgetProperties.text(SWT.Modify).observe(txtVietnameseMeaning);
		IObservableValue vnMeaningExampleObserveValue = PojoProperties.value("vnMeaning").observe(example);
		bindingContext.bindValue(observeTextTxtVietnameseMeaningObserveWidget, vnMeaningExampleObserveValue, null, null);
		//
		IObservableValue observeTextTxtEnglishMeaningObserveWidget = WidgetProperties.text(SWT.Modify).observe(txtEnglishMeaning);
		IObservableValue enMeaningExampleObserveValue = PojoProperties.value("enMeaning").observe(example);
		bindingContext.bindValue(observeTextTxtEnglishMeaningObserveWidget, enMeaningExampleObserveValue, null, null);
		//
		return bindingContext;
	}
	
	public Sentence getExample(){
		return this.example;
	}
	
	
}
